import Vue from 'vue';
import loading from './loading.vue';

let LoadingConstructor = Vue.extend(loading);
let instance;

const Loading = function (options = {}) {
  instance = new LoadingConstructor({
    el: document.createElement('div'),
    data: options,
  }).$mount();
  document.body.appendChild(instance.$el);
  instance.content = options;
};

const open = function () {
  Loading();
};

const close = function () {
  if (instance) {
    instance.close();
  }
};

export default {
  open,
  close
};
